import HttpRequest from '@/utils/HttpRequest';
import { AxiosRequestConfig } from 'axios';
import { getToken } from '@/utils/token';

const baseURL = import.meta.env.VITE_BASE_URL;

const instance = new HttpRequest(baseURL);

const request = async <T>(options: AxiosRequestConfig): Promise<T> => {
  !options.headers && (options.headers = {});
  options.headers['Authorization'] = `Bearer ${getToken()}`;
  return instance.request<T>(options);
};

export default request;
